package com.realtyreg.service;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.realtyreg.domain.entity.users.User;
import com.realtyreg.domain.entity.users.UserRole;
import com.realtyreg.service.form.NameForm;
import com.realtyreg.service.form.PasswordForm;
import com.realtyreg.service.form.Registration;

/**
 * Добавление супер-админа
 * Created by Petro 25.11.12 21:49
 */
public class Starter {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/com/realtyreg/domain/app-context-domain.xml",
                "/com/realtyreg/service/app-context-service.xml");
        UserService userService = context.getBean("userService", UserService.class);
        Registration registration = new Registration();
        registration.setEmail("admin");

        PasswordForm passwordForm = new PasswordForm();
        passwordForm.setNewPassword("123");
        registration.setPasswordForm(passwordForm);

        NameForm nameForm = new NameForm();
        nameForm.setSurName("Super");
        nameForm.setFirstName("Admin");
        registration.setNameForm(nameForm);

        registration.setRole(UserRole.ADMIN.name());
        User admin = userService.create(registration, UserRole.EMPLOYEE);
        admin.setConfirmToken(null);
        admin.setConfirmed(true);
        userService.save(admin);
    }
}
